package com.banyuan.lesson.集合.Colleection.练习;


import java.util.*;

/**
 * 1.随机生成20条狗
 * 颜色随机:白色、黄色、黑色、黄白、黑白
 * 体重随机:[1-50]斤
 * 2.将这些狗依次放入ArrayList中
 * 3.将该list倒序
 * 4.计算list中这些狗的平均体重
 * 5.将体重大于平均值的并且颜色为白色的狗从list中给删除
 * 6.判断该list是否包含体重为20，颜色是白色的狗狗
 * 7.如果存在，则打印该狗狗的下标
 * 8.找到体重最小和最大的狗狗，交换他们的位置
 * 9.对该list按照狗狗的体重降序
 */
public class Dog implements Comparable<Dog>{

    private String color;

    private int weight;

    Random r = new Random(1);

    private String[] dogColor = {"白色","黄色","黑色","黄白","黑白"};

    public Dog() {
        int ran1 = r.nextInt(4);
        int ran2 = r.nextInt(49) + 1;

        this.color = dogColor[ran1];
        this.weight = ran2;
    }

    public Dog(String color, int weight) {
        this.color = color;
        this.weight = weight;
    }

    public String getColor() {
        return color;
    }

    public int getWeight() {
        return weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Dog dog = (Dog) o;
        return weight == dog.weight &&
                Objects.equals(color, dog.color);
    }

    @Override
    public int hashCode() {
        return Objects.hash(color, weight);
    }

    @Override
    public int compareTo(Dog d) {
        if(this.getWeight() == d.getWeight()){
            return this.getColor().compareTo(d.getColor());
        }else{
            return (this.getWeight() - d.getWeight());
        }
    }
}
